<?php
	$this->load->helper('form');
?>

<!DOCTYPE html>
<html lang="zh_CN">
<head>
	<meta charset="utf-8">
	<title>成本收益调查问卷</title>
	<link rel="icon" href="favicon.ico" type="image/x-icon">
	<script src="/js/jquery-1.10.1.min.js"></script>
<!-- City Select -->
	<script src="/js/jquery.cityselect.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#administrative").citySelect({
				nodata:"hidden",
				required:false,
				prov:"<? //echo set_value('prov'); ?>", 
				city:"<? //echo set_value('city'); ?>", 
				dist:"<? //echo set_value('dist'); ?>"
			});
		});
	</script>
<!-- Validation Engine -->
	<link rel="stylesheet" href="/css/validationEngine.jquery.css">
	<script src="/js/jquery.validationEngine-zh_CN.js"></script> 
	<script src="/js/jquery.validationEngine.js"></script> 
	<script type="text/javascript">
		jQuery(document).ready(function(){
			// binds form submission and fields to the validation engine
			jQuery("#form_basic").validationEngine({
				binded:false,
				autoPositionUpdate:true,
				autoHidePrompt:true,
				autoHideDelay:2500,
				showOneMessage:true
			});
		});
	</script>

<!-- Bootstrap Form Builder-->
	<link href="/form_builder/assets/css/lib/bootstrap.min.css" rel="stylesheet">

<!-- Custom Style -->
	<link rel="stylesheet" type="text/css" href="/css/survey.css">	
	<style type="text/css">
		#container {
			/* width: 700px; */
		}
	</style>

</head>
<body>
<div id="container">
<h1 class="header">葡萄园基本情况</h1>
<div id="body">
<form action="/survey" method="post" id="form_survey">

<!-- 第一页：种植基本信息 -->
<div class="page" id="1" style="display: block;">
<!-- 1.1 省市 -->
	<div class="q-div">
		<div class="q-title">葡萄园所在的省、市以及区县</div>
		<div class="row">
			<div class="span4" id="administrative">
				<select class="prov input-small validate[required]" id="prov" name="prov"></select>
				<select class="city input-small validate[condRequired[prov]]" id="city" name="city" style="display: none;"></select>
				<select class="dist input-small validate[condRequired[prov,city]]" id="dist" name="dist" style="display: none;">
					<option value="default">请选择</option>
				</select>
			</div>
			<div class="span4">
				<p class="q-help">提示：先选择省（直辖市），再依次选择市和区县</p>
				<p class="q-example"></p>
			</div>
		</div>
	</div>

<!-- 1.2 地址 -->
	<div class="q-div">
		<div class="q-title">葡萄园的详细地址</div>
		<div class="row">
			<div class="span4">
				<input id="address" name="address" type="text" placeholder="点击填入" class="input-xlarge>"/>
			</div>
			<div class="span4">
				<p class="q-help">提示：省市区信息无需重复填写</p>
				<p class="q-example">填写示例：池口镇彭姥岭村（灵峰庄园南）</p>
			</div>
		</div>
	</div>

<? 
	/**
	 *
	 *
	 */
	function _add_question($q_data, $input_data, $help_data) {
		// Param Validation
		if(is_array($q_data) && !isset($q_data['q-title'])) {
			echo 'Error: You don\'t have a title!';
		}
		if(!is_array($input_data)) {
			echo 'Error: the $input_data is not an array!';
		}
		if(is_array($input_data) && !isset($input_data['type'])) {
			echo 'Error: Your Input doesn\'t have a type!';
		}

		// Main DIV and Title
		$content = '<div class="q-div ';
		if(is_array($q_data)) {
			$content .= $q_data['class'].'"';
			unset($q_data['class']);

			$q_title = $q_data['q-title'];
			unset($q_data['q-title']);

			$span_input = (isset($q_data['span-input']))?$q_data['span-input']:'4';
			unset($q_data['span-input']);

			$content .= _attr_Parse($q_data);
		} else {
			$q_title = $q_data;
			$content .= '>';
		}

		$content .= '<div class="q-title">'.$q_data.'</div><div class="row"><div class="span'.$span_input.'">';

		// Input DIV
		switch ($input_data['type']) {
			case 'select':
				$content .= _add_select($input_data['select_data']).'</div>';
				break;
			case 'text':
				$content .= form_input($input_data['text_data']).'</div>';
				break;
			case 'radio':
				$content .= '';
				break;
			default:
				# code...
				break;
		}

		// Help DIV

		// Return string
		return $content;
}

	function _attr_Parse($attrs) {
		$attributes = '';
		foreach ($attrs as $key => $value) {
			$attributes .= ' '.$key.'="'.$value.'"';
		}
		return $attributes.'>';
	}

	function _add_select($select_data) {
		// $option_content = '';
		// if(isset($select_data['options_data'])) {
		// 	$option_content .= _add_options($select_data['options_data']);
		// }
		// unset($select_data['options_data']);
		// $select_input_content = '<select class="';
		// $select_input_content .= $select_data['class'].'"';
		// unset($select_data['class']);
		// $select_input_content .= _attr_Parse($select_data).$option_content.'</select>';
		
		// return $select_input_content;
		return form_dropdown($select_data['name'], $select_data['options_data'], '', $select_data['js']);
	}

	// function _add_options($options_data) {
	// 	$option_content = '';
	// 	if(isset($options_data['default'])) {
	// 		$option_content = '<option value="">'.$options_data['default'].'</option>';
	// 		unset($options_data['default']);
	// 	}
	// 	foreach ($options_data as $value => $label) {
	// 			$option_content .= '<option value="'.$value.'">'.$label.'</option>';
	// 	}
	// 	return $option_content;
	// }
?>

	<?php
		$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '16',
              'style'       => 'width:50%',
            );

		echo form_input($data);
    ?>
</div>
</form>
</div>